package cn.lzy;

import cn.lzy.cache.JpaCache.Article.ArtiRepository;
import cn.lzy.configbean.Person;
import cn.lzy.configbean.Student;
import cn.lzy.configbean.User;
import cn.lzy.controller.ChapterController;
import cn.lzy.mybaties.Article;
import cn.lzy.mybaties.ArticleMapper;
import cn.lzy.mybaties.Comment;
import cn.lzy.mybaties.CommentMapper;
import cn.lzy.mybaties.jpa.Discuss;
import cn.lzy.mybaties.jpa.DiscussRepository;
import cn.lzy.mybaties.redis.Address;
import cn.lzy.mybaties.redis.Family;
import cn.lzy.mybaties.redis.PersonRepository;
import cn.lzy.profielconfig.DBConnector;
import cn.lzy.smileconfig.MyConfig;
import cn.lzy.smileconfig.MyProperties;
import cn.lzy.smileconfig.SmileProperties;
import javafx.application.Application;
import org.hibernate.loader.collection.OneToManyJoinWalker;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationContextFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.security.RunAs;
import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/*
* @Author WeiKaiYe
* @CreateTime 2023/9/18-17:38
**/

@RunWith(SpringRunner.class) //测试运行器，并加载spring boot 测试注解
@SpringBootTest // 标记单元测试类，并加载项目的上下文环境ApplicationContext
public class ChapterTestApplication {

    @Autowired //Autowired 注入ChapterController类
    ChapterController chapterController;

    @Autowired
    Student student;

    @Autowired
    Person person;

    @Autowired
    User user;

    @Value("567")
    int id;

    @Autowired
    SmileProperties smileProperties;

    @Autowired
    ApplicationContext applicationContext;

//    @Autowired
//    DBConnector dbConnector;

    @Autowired
    private CommentMapper commentMapper;

    /*@Autowired
    private ArticleMapper articleMapper;*/

    @Autowired
    DiscussRepository mDiscussRepository;

    /*@Autowired
    JpaRepository mJpaRepository;*/

    @Autowired
    PersonRepository mPersonRepository;

    @Autowired
    ArtiRepository mArtiRepository;

    @Test
    public void contextLoads(){

        // JPA 测试
/*        List<Discuss> list = mDiscussRepository.findByAuthorNotNull();
        System.out.println(list);

        Optional<Discuss> list1 = mDiscussRepository.findById(1);
        System.out.println(list);*/


 /*      System.out.println(commentMapper.findById(2));

        //查询语句指定的id信息
        Comment comment = commentMapper.findById(2);
        System.out.println(comment);

        //更新语句数据
        Comment comment1 = new Comment();
        int index = commentMapper.updateComment(comment1);
*/
        /*Article article = articleMapper.selectArticle(1);
        System.out.println(article);*/


/*        System.out.println("单元测试返回的数据---"+ chapterController.sayHello());

        System.out.println("单元测试返回的数据---student----"+ student);
        System.out.println("单元测试返回的数据---user----"+ user);
        System.out.println("单元测试返回的数据---id----"+ id);

        System.out.println("单元测试返回的数据---person----"+ person);
        System.out.println(" ");
        System.out.println("单元测试返回的数据---smileProperties----"+ smileProperties);
        System.out.println(" ");
        System.out.println("-----------成功输出啦！-----------");*/

        /*MyProperties myProperties =(MyProperties) applicationContext.getBean("myProperties1");
        if (myProperties == null){
            System.out.println("MyProperties 类注入加载不成功！");
        }else {
            myProperties.getResult();
        }
        System.out.println(" ");

        dbConnector.config();
        System.out.println(dbConnector.config( ));*/
    }

    @Test
    public void saveRedisPerson() {
        cn.lzy.mybaties.redis.Person personRedis = new cn.lzy.mybaties.redis.Person();
        personRedis.setFirstname("喵");
        personRedis.setLastname("汪");
        Address address = new Address();
        address.setCity("南宁");
        address.setCountry("中国");
        personRedis.setAddress(address);
        List<Family> list = new ArrayList<>();
        Family dog = new Family("小花猫","喵喵喵");
        Family cat = new Family("小旺财","汪汪汪");
        list.add(dog);
        list.add(cat);
        personRedis.setFamilyList(list);
        cn.lzy.mybaties.redis.Person personResult = mPersonRepository.save(personRedis);
        System.out.println(personResult);
    }

    @Test
    public void Wrise(){

    }
}
